import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "工作台", icon: "icon_menu_gongzuotai备份 28 (7)" },
      },
    ],
  },

  {
    path: "/manage-base-info",
    component: Layout,
    redirect: "/manage-base-info/warehouse",
    name: "Manage",
    meta: { title: "基础信息管理", icon: "icon_menu_gongzuotai备份 29" },
    children: [
      {
        path: "warehouse",
        name: "Warehouse",
        component: () => import("@/views/manage/index"),
        meta: { title: "仓库管理", icon: "椭圆形备份 50" },
      },
      {
        path: "area",
        name: "Area",
        component: () => import("@/views/manage/area/index"),
        meta: { title: "库区管理", icon: "椭圆形备份 50" },
      },
      {
        path: "location",
        name: "Location",
        component: () => import("@/views/manage/location/index"),
        meta: { title: "库位管理", icon: "椭圆形备份 50" },
      },
      {
        path: "location-view",
        name: "LocationView",
        component: () => import("@/views/manage/location-view/index"),
        meta: { title: "库区视图", icon: "椭圆形备份 50" },
      },
      {
        path: "goods",
        name: "Goods",
        component: () => import("@/views/manage/goods/index"),
        meta: { title: "货品管理", icon: "椭圆形备份 50" },
      },
      {
        path: "goods-type",
        name: "GoodsType",
        component: () => import("@/views/manage/goods-type/index"),
        meta: { title: "货品类型管理", icon: "椭圆形备份 50" },
      },
    ],
  },

  {
    path: "/manage-business",
    component: Layout,
    redirect: "/manage-business/goods-owner",
    name: "ManageBusiness",
    meta: { title: "商务管理", icon: "icon_menu_gongzuotai备份 30" },
    children: [
      {
        path: "goods-owner",
        name: "GoodsOwner",
        component: () => import("@/views/managebusiness"),
        meta: { title: "货主管理", icon: "椭圆形备份 50" },
      },
      {
        path: "task-picking",
        name: "TaskPicking",
        component: () => import("@/views/managebusiness/task-picking"),
        meta: { title: "承运商管理", icon: "椭圆形备份 50" },
      },
    ],
  },

  {
    path: "/manage-storage",
    component: Layout,
    redirect: "/manage-storage/list",
    name: "ManageStorage",
    meta: { title: "库内管理", icon: "icon_menu_gongzuotai备份 31" },
    children: [
      {
        path: "list",
        name: "List",
        component: () => import("@/views/manage-storage/index.vue"),
        meta: { title: "盘点单", icon: "椭圆形备份 50" },
      },
      {
        path: "list-task",
        name: "ListTask",
        component: () => import("@/views/manage-storage/list-task"),
        meta: { title: "盘点任务", icon: "椭圆形备份 50" },
      },
      {
        path: "storage-lose-profit",
        name: "StorageLoseProfit",
        component: () => import("@/views/manage-storage/storage-lose-profit"),
        meta: { title: "库存损益", icon: "椭圆形备份 50" },
      },
      {
        path: "latest-storage",
        name: "LatestStorage",
        component: () => import("@/views/manage-storage/latest-storage"),
        meta: { title: "实时库存", icon: "椭圆形备份 50" },
      },
    ],
  },

  {
    path: "/manage-storage-in",
    component: Layout,
    redirect: "/manage-storage-in/list",
    name: "ManageStorageIn",
    meta: { title: "入库管理", icon: "icon_menu_gongzuotai备份 33" },
    children: [
      {
        path: "in-list",
        name: "InList",
        component: () => import("@/views/manage-storage-in/index"),
        meta: { title: "入库单", icon: "椭圆形备份 50" },
      },
      {
        path: "task-receive",
        name: "TaskReceive",
        component: () => import("@/views/manage-storage-in/task-receive"),
        meta: { title: "收货任务", icon: "椭圆形备份 50" },
      },
      {
        path: "task-add",
        name: "TaskAdd",
        component: () => import("@/views/manage-storage-in/task-add"),
        meta: { title: "上架任务", icon: "椭圆形备份 50" },
      },
    ],
  },
  {
    path: "/manage-storage-out",
    component: Layout,
    redirect: "/manage-storage-out/list",
    name: "ManageStorageOut",
    meta: { title: "出库管理", icon: "icon_menu_gongzuotai备份 33" },
    children: [
      {
        path: "out-list",
        name: "OutList",
        component: () => import("@/views/manage-storage-out/index.vue"),
        meta: { title: "出库单", icon: "椭圆形备份 50" },
      },
      {
        path: "task-picking",
        name: "OutTaskPicking",
        component: () => import("@/views/manage-storage-out/task-picking"),
        meta: { title: "拣货任务", icon: "椭圆形备份 50" },
      },
      {
        path: "manage-task-transfer",
        name: "OutManageTaskTransfer",
        component: () =>
          import("@/views/manage-storage-out/manage-task-transfer"),
        meta: { title: "交接任务", icon: "椭圆形备份 50" },
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
